<?php
/**
 * ActionBar.php
 *
 * @author		b.wenneker <b.wenneker@gmail.com>, 2010
 */
class View_Helper_ActionBar extends Zend_View_Helper_Abstract{
	
	protected $_actions = array();
	
	/**
	 * actionBar() - Returns itself.
	 *
	 * @author b.wenneker <b.wenneker@gmail.com>, 2010
	 */
	public function actionBar(){
		
		return $this;
	}
	
	/**
	 * addAction() - Adds an actions to the actionbar.
	 *
	 * @author b.wenneker <b.wenneker@gmail.com>, 2010
	 * @param string $label
	 * @param string $url
	 * @return View_Helper_ActionBar Returns itself to allow chaining.
	 */
	public function addAction($label, $url){
		
		$this->_actions[] = array(
			'label'		=> $label,
			'url'		=> $url
		);
		
		return $this;
	}
	
	/**
	 * _renderActions() - Renders the actions as a list of anchor tags.
	 *
	 * @author b.wenneker <b.wenneker@gmail.com>, 2010
	 */
	protected function _renderActions(){
		
		$result		= '';
		
		foreach((array)$this->_actions as $action){
			$result .= sprintf('<a href="%s" title="%s">%s &rsaquo;</a>',
				$action['url'],
				$action['label'],
				$action['label']
			);
		}
		
		return $result;
	}
	
	/**
	 * __toString() - Converts this object to string.
	 *
	 * @author b.wenneker <b.wenneker@gmail.com>, 2010
	 */
	public function __toString(){
		$header		= '<h1>More functionality</h1>';
		$actions	= $this->_renderActions();
		
		return $header . $actions;
	}
}